package xyz.lwm.lazycat.beans;

import xyz.lwm.lazycat.utility.It;
import xyz.lwm.lazycat.utility.StrPool;
import xyz.lwm.lazycat.utility.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * app runners
 *
 * @author lwm
 */
class AppRunners {

    private static final String JAVA_COMMAND  = "sun.java.command";

    private final List<AppRunner> runners = new ArrayList<>();

    public void add(AppRunner runner) {
        runners.add(runner);
    }

    public void run() {
        It.of(System.getProperty(JAVA_COMMAND))
                .filter(StringUtil::isNotBlank).also(cmd -> {
            String[] args = cmd.split(StrPool.STR_SPACE);
            runners.forEach(runner -> runner.run(args));
        });
    }

}
